package com.example.mybank.tool;

public class TokenHelper {
    public static boolean isValid(Long value,Long userID) throws MyException {
        if(value==null){
            throw new MyException(ResultCode.Value_Is_Null);
        }else if(value==0){
            throw new MyException(ResultCode.Buycount_NOT_Pass);
        }
        // 核对正确的Value
        Long value_correct = RedisTool.usersToken_get(userID);
        if(value_correct==null){
            // 值未null，（在该网页停留太久/未通过初筛/按钮点击次数太多）
            throw new MyException(ResultCode.Value_Not_Exist);
        }
        if(!value.equals(value_correct)){
            // value不一致
            throw new MyException(ResultCode.Value_Not_Correct);
        }

        return true;
    }
}
